/*
 * // +-------------------------------------------------------------------------------------------------
 * // |                 有你就好 [ 有节骨乃坚，无心品自端 ]     <http://encoding.wang>
 * // +-------------------------------------------------------------------------------------------------
 * // |                             独在异乡为异客         每逢佳节倍思亲
 * // +-------------------------------------------------------------------------------------------------
 * // |                 联系:   <707069100@qq.com>      <http://weibo.com/513778937>
 * // +-------------------------------------------------------------------------------------------------
 */

// -----------------------------------------------------------------------------------------------------
// +----------------------------------------------------------------------------------------------------
// |                   ErYang出品 属于小极品          共同学习    共同进步
// +----------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------


package wang.encoding.mroot.admin.common.util


import org.apache.shiro.SecurityUtils
import org.apache.shiro.session.Session
import org.apache.shiro.subject.Subject
import java.io.Serializable

/**
 * shiro session 工具类
 *
 * @author ErYang
 */

object ShiroSessionUtil {


    /**
     * 移除 key-value
     *
     * @param key String
     */
    fun removeAttribute(key: String) {
        this.getSession().removeAttribute(key)
    }

    // -------------------------------------------------------------------------------------------------

    /**
     * 设置 key-value
     *
     * @param key String
     * @param value Any
     */
    fun setAttribute(key: String, value: Any?) {
        this.getSession().setAttribute(key, value)
    }

    // -------------------------------------------------------------------------------------------------

    /**
     * 根据 key 得到 value
     *
     * @param key String
     *
     * @return Any
     */
    fun getAttribute(key: String): Any? {
        return this.getSession().getAttribute(key)
    }

    // -------------------------------------------------------------------------------------------------

    /**
     * 得到 shiro sessionId
     *
     * @return sessionId String
     */
    fun getSessionId(): Serializable? {
        return this.getSession().id
    }

    // -------------------------------------------------------------------------------------------------

    /**
     * 得到 shiro session
     *
     * @return Session
     */
    fun getSession(): Session {
        val currentSubject: Subject = SecurityUtils.getSubject()
        return currentSubject.session
    }

    // -------------------------------------------------------------------------------------------------

}

// -----------------------------------------------------------------------------------------------------

// End ShiroSessionUtil class

/* End of file ShiroSessionUtil.kt */
/* Location: ./src/main/kotlin/wang/encoding/mroot/admin/common/util/ShiroSessionUtil.kt */

// -----------------------------------------------------------------------------------------------------
// +----------------------------------------------------------------------------------------------------
// |                           ErYang出品 属于小极品  O(∩_∩)O~~   共同学习    共同进步
// +----------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------
